using System.Collections.Generic;
using System.Linq;

namespace GoldenKnowledge.Data.Indexing
{
    public class ProblemSearchEngine : IProblemIndexer, IQueryExecutor
    {
        private readonly IProblemQueryChecker problemQueryChecker;
        private readonly List<IProblem> problems = new List<IProblem>();

        public ProblemSearchEngine(IProblemQueryChecker problemQueryChecker)
        {
            this.problemQueryChecker = problemQueryChecker;
        }

        #region IProblemIndexer Members

        public void Consume(IProblem problem)
        {
            problems.Add(problem);
        }

        #endregion

        #region IQueryExecutor Members

        public IEnumerable<IProblem> Run(Query query)
        {
            return problems.Where(x => problemQueryChecker.Accepts(x, query));
        }

        #endregion
    }
}